package com.boot.project.admin.controller.manage;

import com.boot.project.admin.service.AuthService;
import com.boot.project.core.model.result.ProfileResult;
import com.boot.project.module.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 针对thymeleaf的同步渲染控制器
 * @author: tsing
 * @create: 2021-03-04 21:56
 */
@Controller
public class RenderController {

    @Autowired
    private AuthService authService;

    /**
     * 跳转至登录页
     * @return
     */
    @GetMapping("/login")
    public String login() {
        return "/login";
    }

    /**
     * 跳转至首页
     * @param model 数据模型
     * @return
     */
    @GetMapping({"/admin", "/"})
    public String admin(Model model) {
        ProfileResult profile = authService.profile();
        model.addAttribute("firstLogin", profile.getFirstLogin());
        model.addAttribute("username", profile.getUsername());
        model.addAttribute("menuTree", profile.getResult().getMenus());
        return "/index";
    }

    /**
     * 请求首页的数据
     * @param model 数据模型
     * @return
     */
    @GetMapping("home")
    public String home(Model model) {
        ProfileResult profile = authService.profile();
        model.addAttribute("menu", profile.getResult().getMenus());
        return "/home/dashboard";
    }

    /**
     * 请求用户页
     * @return
     */
    @GetMapping("/users")
    public String users() {
        return "/user/list";
    }

    /**
     * 请求角色页
     * @return
     */
    @GetMapping("/roles")
    public String roles() {
        return "/role/list";
    }

    /**
     * 请求资源页
     * @return
     */
    @GetMapping("/resources")
    public String resources() {
        return "/resource/list";
    }

    /**
     * 请求日志页
     * @return
     */
    @GetMapping("/logs")
    public String logs() {
        return "/log/list";
    }
}
